<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* Get Filenames
*
* Reads the specified directory and builds an array containing the filenames.  
* Any sub-folders contained within the specified path are read as well.
*
* @access    public
* @param    string    path to source
* @param    bool    whether to include the path as part of the filename
* @param    array    optionally include an array to be merged with results
* @return    array
*/    
function get_dynamic_filenames($source_dir, $include_path = FALSE, $filedata = array())
{
    if ($fp = @opendir($source_dir))
    {
        while (FALSE !== ($file = readdir($fp)))
        {
            if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.')
            {
                 $filedata = array_merge( get_filenames($source_dir.$file."/", $include_path, $filedata), $filedata );
            }
            elseif (substr($file, 0, 1) != ".")
            {
                $filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file;
            }
        }
        return $filedata;
    }
}

?>